# def sum1(a, b):
#     return a + b
# print(sum1(1, 2))
# 匿名函数
fun = lambda a, b: a + b
print(fun(1, 2))

# map()函数，映射
a = [1, 2, 3, 4, 5, 6]
# def f(x):
#     return x**2
# result = map(f, a)
result = map(lambda x: x ** 2, a)
print(list(result))

# reduce()函数，累积
from functools import reduce

result = reduce(lambda x, y: x + y, a)
print(result)

# filter()函数，过滤
result = filter(lambda x: x % 2 == 0, a)
print(list(result))

a = [0, 234, 21, 9, 87, 49, 0, 2, 7]
result = filter(lambda x: x != 0, a)  # 过滤0
print(list(result))
# 把a转换为大整数
result = 0
mul = 1
for i in a[::-1]:
    result += i * mul
    mul *= 10 ** len(str(i))
print(result)
result = reduce(lambda x, y: x * 10 ** len(str(y)) + y, a)
print(result)
